<?php

namespace App\Console;

use App\Jobs\CheckCertValidJob;
use App\Jobs\QueryLoanRequestResultPushJob;
use App\Jobs\QueryLoanResultJob;
use App\Models\RepaySummary;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')
        //          ->hourly();
        /**
         * 每天00:00检查更改到期身份证有效状态
         */
//        $schedule->job(new CheckCertValidJob())->dailyAt('12:30')->appendOutputTo(storage_path('cron/cron_check_cert_valid.log'));
        $schedule->command('check:cert_valid')->dailyAt('00:00')->appendOutputTo(storage_path('cron/cron_check_cert_valid.log'));


        /**
         * 用户申请放款结果 每五分钟请求一次
         */
        //$schedule->job(new QueryLoanResultJob())->everyFiveMinutes()->appendOutputTo(storage_path('cron/query_loan_result.log'));
        $schedule->command('apply_append:cron seeLoanRes')->everyFiveMinutes()->appendOutputTo(storage_path('cron/query_loan_result.log'));

        /**
         * 每五分钟请求查询申请中的用户授信结果
         */
//        $schedule->job(new QueryLoanRequestResultPushJob())->everyFiveMinutes()->appendOutputTo(storage_path('cron/cron_query_loan_request_result.log'));
        $schedule->command('push:loan_request_result')->everyFiveMinutes()->appendOutputTo(storage_path('cron/cron_query_loan_request_result.log'));

        /**
         * 检查已同步用户未上传身份证的
         */
        $schedule->command('checkIdCardUpload')->everyFiveMinutes()->appendOutputTo(storage_path('cron/cron_id_card_upload.log'));
        /**
         * 同步用户信息失败重试
         */
//        $schedule->command('user:failed sync')->everyMinute()->appendOutputTo(storage_path('cron/cron_user_sync.log'));
        $schedule->command('user:failed solve')->everyFiveMinutes()->appendOutputTo(storage_path('cron/cron_user_sync_solve.log'));

        /**
         * 检查需要进入授信申请队列的数据
         */
        $schedule->command('check:loan_request_to_apply')->cron('*/3 * * * * ')->appendOutputTo(storage_path('cron/cron_loan_request_to_apply.log'));

        /**
         * 检查需要重试的授信
         */
        //$schedule->command('check:loan_request_retry')->dailyAt('00:05')->appendOutputTo(storage_path('cron/cron_loan_request_retry.log'));
        /**
         * 还款相关
         */
        $schedule->command('repay:cron month')->everyFiveMinutes()->appendOutputTo(storage_path('cron/cron_repay_month.log')); //月报接口结果获取
        $schedule->command('repay:cron common')->everyFiveMinutes()->appendOutputTo(storage_path('cron/cron_repay_common.log')); //公共接口结果获取
        $schedule->command('repay:cron money')->everyFiveMinutes()->appendOutputTo(storage_path('cron/cron_repay_money.log')); //资金接口结果获取
        $schedule->command('repay:cron buckle')->everyFiveMinutes()->appendOutputTo(storage_path('cron/cron_repay_buckle.log')); //裸扣获取结果
        $schedule->command('repay:cron moneyNotify')->everyTenMinutes()->appendOutputTo(storage_path('cron/cron_repay_money_notify.log')); //获取通知资方的老数据的老光大的信息


        //自动还款,l
        $schedule->command('repay:repay_auto money_jinxiao')->twiceDaily(8,22)->appendOutputTo(storage_path('cron/cron_repay_auto.log'));
        $schedule->command('repay:repay_auto money_other')->twiceDaily(8,18)->appendOutputTo(storage_path('cron/cron_repay_auto_other.log'));
        $schedule->command('repay:repay_auto money_other')->dailyAt(22)->appendOutputTo(storage_path('cron/cron_repay_auto_other.log'));

        //每30分钟运行一次
        $schedule->command('repay:cron jsSync')->hourlyAt(30)->appendOutputTo(storage_path('cron/cron_repay_js_sync.log')); //晋商每天下午4、5点会主动扣逾期账户的钱，所以要同步晋商的数据
        $schedule->command('repay:repay_auto setMoney')->dailyAt(23)->appendOutputTo(storage_path('cron/cron_repay_auto_money.log')); //修复record为2 其他的分表不为2 重新唤起
        $schedule->command('repay:repay_auto setOldGuangDa')->dailyAt('15:00')->appendOutputTo(storage_path('cron/cron_repay_auto_old_gd.log')); //每天的老光大,异常数据重新请求资方

        /**
         * 还款推送
         */
//        $schedule->command('repay:cron JRepay')->dailyAt('9:00')->appendOutputTo(storage_path('cron/cron_repay_JRepay.log')); //还款提醒每天九点发送极光推送
//        $schedule->command('repay:cron JToday')->dailyAt('9:00')->appendOutputTo(storage_path('cron/cron_repay_JToday.log')); //还款提醒每天九点发送极光推送
//        $schedule->command('repay:cron JOverdue')->dailyAt('9:00')->appendOutputTo(storage_path('cron/cron_repay_JOverdue.log')); //逾期提醒每天九点发送极光推送
//        $schedule->command('repay:sms overdue')->dailyAt('9:00')->appendOutputTo(storage_path('cron/cron_repay_sms.log')); //还款逾期每天九点发送短信提醒

        /*
         * 生日推送
         * */
        $schedule->command('birthday:cron')->dailyAt('9:00')->appendOutputTo(storage_path('cron/birthday.log'));

        //保留7天前队列失败异常记录
        $schedule->command('failed:delete')->dailyAt('1:00')->appendOutputTo(storage_path('cron/failed_delete.log'));

        //风控查询
        $schedule->command('risk:cron queryRiskResult')->everyFiveMinutes()->appendOutputTo(storage_path('cron/query_risk_result.log'));
        //提交风控
        $schedule->command('risk:cron checkSpiderStatus')->everyMinute()->appendOutputTo(storage_path('cron/check_spider_status.log'));
        /**
         * 芝麻信用爬虫结果
         */
        $schedule->command('risk:cron alipay')->everyMinute()->appendOutputTo(storage_path('cron/risk_spider_alipay.log'));
        /**
         * 运营商爬虫结果
         */
        $schedule->command('risk:cron reptile')->everyMinute()->appendOutputTo(storage_path('cron/risk_reptile.log'));
        /**
         * 每天凌晨清空减免数据表
         */
        $schedule->command('collection:cron clearRelief')->dailyAt('0：01')->appendOutputTo(storage_path('cron/collection_clear_relief.log'));

        /**
         * 商户代偿（销账）接口(获取销帐结果)，每10分钟跑一次
         */
        $schedule->command('collection:cron compensate')->everyTenMinutes()->appendOutputTo(storage_path('cron/collection_compensate.log'));

        /**
         * 昨日放款数据发邮件，每天早上5:30点
         */
        $schedule->command(' mail:send  loan')->dailyAt('5:30')->appendOutputTo(storage_path('cron/mail_loan.log'));

        /**
         * 前七日未要款数据发邮件，每天早上3:05
         */
        $schedule->command(' mail:send  waitLoan')->dailyAt('3:05')->appendOutputTo(storage_path('cron/mail_wait_loan.log'));

        /**
         * 昨日逾期数据发邮件，每天早上3:30
         */
        $schedule->command(' mail:send  overdueOne')->dailyAt('3:30')->appendOutputTo(storage_path('cron/mail_overdue_one.log'));

        /**
         * 逾期数据发邮件，每天早上4:10
         */
        $schedule->command(' mail:send  overdueMore')->dailyAt('4:10')->appendOutputTo(storage_path('cron/mail_overdue_more.log'));

        /**
         * 昨天平台还款数据发邮件，每天早上3:40
         */
        $schedule->command(' mail:send  repaymentcommon')->dailyAt('3:40')->appendOutputTo(storage_path('cron/mail_repayment_common.log'));

        /**
         * 昨天资方还款数据发邮件，每天早上4:00
         */
        $schedule->command(' mail:send  repaymentmoney')->dailyAt('4:00')->appendOutputTo(storage_path('cron/mail_repayment_money.log'));

        /**
         * 每5分钟插入埋点数据到数据库
         */
        $schedule->command('user-follow:data insert')->everyFiveMinutes()->appendOutputTo(storage_path('cron/user-follow.log'));

        /**
         * 每小时50分插入埋点数据到 user_follow_cache_hour
         */
        $schedule->command('user-follow:data cacheHour')->hourlyAt(50)->appendOutputTo(storage_path('cron/user-follow-hour.log'));

        /**
         * 每天1:50插入一次埋点数据到 user_follow_cache_day
         */
        $schedule->command('user-follow:data cacheDay')->dailyAt('1:50')->appendOutputTo(storage_path('cron/user-follow-day.log'));

        /**
         * 每日更新罚息
         */
        $schedule->command('repay:cron upFines')->dailyAt('00:10')->appendOutputTo(storage_path('cron/up_fines.log'));


//        /**
//         * 放款超额凌晨重试（自动放款）
//         */
//        $schedule->command('retry-apply:cron retry')->dailyAt("00:25")->appendOutputTo(storage_path('cron/cron_retry_apply_auto_apply.log'));

        /**
         * 每日09:00, 23:55间每5分钟 晋商超额的数据
         */

        $schedule->command('apply_append:cron serachLoanUpdate')->everyFiveMinutes()->between('09:00', '23:55')->appendOutputTo(storage_path('cron/serachLoanUpdate.log'));


        /**
         * 催收
         */
        //每天04:10 催收系统更新T-3
        $schedule->command('repayment:cron propelNews --tn=3')->dailyAt('04:10')->appendOutputTo(storage_path('cron/collection_propel_news.log'));
        //每天05:10 催收系统未分案更新案件
        $schedule->command('collection:cron update')->dailyAt('05:10')->appendOutputTo(storage_path('cron/collection_update.log'));

        /**
         * 每日的还款预计表，每天早上9：30点
         */
        $schedule->command('mail:send huankuanT')->dailyAt('9:30')->appendOutputTo(storage_path('cron/mail_huankuanT.log'));
        /**
         * T-2还款预计表，每天早上4点
         */
        $schedule->command('mail:send huankuanT2')->dailyAt('4:00')->appendOutputTo(storage_path('cron/mail_huankuanT2.log'));

        /**
         * 全量客户数及客户贷款余额，每天早上8：30点
         *
         */
        $schedule->command('mail:send normalExce')->monthlyOn(1, '8:30')->appendOutputTo(storage_path('cron/mail_normalExce.log'));

        /**
         * 修复银行卡类型
         */
        $schedule->command('repair_bank_card')->everyMinute()->appendOutputTo(storage_path('cron/repair_bank_card.log'));
        /**
         * 还款监控，1、3、5、7、9、11、13、15、17、19、21、23
         */
        $schedule->command('mail:send repaymentMonitor')->cron('0 1,3,5,7,9,11,13,15,17,19,21,23 * * *')->appendOutputTo(storage_path('cron/mail_repaymentMonitor.log'));
        /**
         * 每天00:00修复用户身份证信息
         */
        $schedule->command('repair:sfz')->dailyAt('00:01')->appendOutputTo(storage_path('cron/repair_sfz.log'));

    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}
